<template>
    <div>
        <Modal width="820"
               v-model="modal.modalUploadFlag"
               @on-cancel="cancel"
               title="导入文件">
            <div class="modalDiv"></div>
            <Upload
                    accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,&nbsp;application/vnd.ms-excel"
                    :before-upload="handleUpload"
                    action="">
                <Button id="uploadId" icon="ios-cloud-upload-outline">导入文件</Button>
            </Upload>
        </Modal>
    </div>
</template>
<script>

    export default {
        name: "uplodaModal",
        props: {
            modal: {
                modalUploadFlag:false
            }
        },
        data(){
            return{
                token:window.sessionStorage.getItem('token'),
            }
        },
        methods: {
            cancel() {

            },
            handleUpload(file){
                let form = new FormData();
                form.append("file", file)
                this.http.post(this.modal.url,form).then(res=>{
                    if(res.data.status){
                        this.$Message.success('导入完成！')
                    }
                    this.$emit("changeStatus",true)
                    this.modal.modalUploadFlag = false;
                }).error(res=>{
                    this.$Message.error(res.data)
                    this.modal.modalUploadFlag = false;
                })
            }
        },
        watch:{
            'modal.modalUploadFlag'(e){
                if(e){
                    console.log(this.access_token)
                    document.getElementById('uploadId').click()
                }
            }
        },
    }
</script>

<style scoped>

</style>